/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reppconn;

import java.io.IOException;
import java.util.ArrayList;
import org.annolab.tt4j.TokenHandler;
import org.annolab.tt4j.TreeTaggerException;
import org.annolab.tt4j.TreeTaggerWrapper;

/**
 *
 * @author Nargisse
 */
public class LemmatiseurHandler{
   
    private TreeTaggerWrapper<String> tt;   
    private ArrayList<String> termesPasLem;
    private ArrayList<String> termesLem;
    
    public LemmatiseurHandler(){
        
        termesLem = new ArrayList<String>();
        tt = new TreeTaggerWrapper<String>();
        // Lemmatiseur
        System.setProperty("treetagger.home", "C:\\Program Files\\TreeTagger");
        try {
                tt.setModel("C:\\Program Files\\TreeTagger\\model\\french.par:utf-8");
                tt.setHandler(new TokenHandler<String>() {

                    @Override
                    public void token(String token, String pos, String lemma) {
                        //System.out.println(token + "\t" + pos + "\t" + lemma);
                        termesLem.add(lemma);
                    }
            });
        } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }
        
    }
    
    public void lemmatiser() throws IOException, TreeTaggerException {
        // Lemmatisation
       
        //System.out.println("Je SUIS DS LEMMATISER");
        tt.process(termesPasLem);
    }
    
     public void destroyLemmatiser() throws IOException, TreeTaggerException {
		// Lemmatisation
                System.out.println("Je SUIS DS DESTROYLEMMATISER");
		tt.destroy();
    }
    
    public ArrayList<String> getListTermeLem(){
        return this.termesLem;
    }
    
    public void clearListTermLem(){
        this.termesLem.clear();
    }
    
    public void setListTermeNonLem(ArrayList<String> termesnonLem){
        this.termesPasLem = termesnonLem;
    }
    
    //Si vrai alors on ne veut pas appeler couperToken(String token)
    public boolean isSmallerToken(String token){
        if(token.length() < 8){
            return true;
        }else return false;
    }
    
    //restreindre le token a 7 caracteres max
    public String couperToken(String token){
        return token.substring(0, 7);
    }
    
}
